using System;
using System.Reflection;
using CriticalSystems.Instrumentation.Internal;

namespace CriticalSystems.Instrumentation
{
    public static class Tracing
    {
        public static void In()
        {
            string method;
            GetTrace(out method).In(method);
        }

        public static void Out()
        {
            string method;
            GetTrace(out method).Out(method);
        }

        public static void Out(Exception ex)
        {
            string method;
            GetTrace(out method).Out(method, ex);
        }

        public static void Info(string text, params object[] parameters)
        {
            string method;
            GetTrace(out method).Info(method, text, parameters);
        }

        public static void Warning(string text, params object[] parameters)
        {
            string method;
            GetTrace(out method).Warning(method, text, parameters);
        }

        public static void Error(string text, params object[] parameters)
        {
            string method;
            GetTrace(out method).Error(method, text, parameters);
        }

        public static void Error(Exception ex)
        {
            string method;
            GetTrace(out method).Error(method, ex);
        }

        private static Trace GetTrace(out string method)
        {
            var callingMethod = ReflectionHelper.GetCallingMethod();
            method = callingMethod.Name;
            return new Trace(callingMethod.DeclaringType.FullName);
        }
    }
}